package com.tusuo.stds.ui.lab;

import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.tusuo.stds.R;
import com.tusuo.stds.ui.BaseToolbarActivity;
import com.tusuo.stds.ui.ToolbarOwner;
import com.tusuo.stds.ui.UISwitchButton;
import com.tusuo.stds.util.Utils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.CheckedChange;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.ColorRes;
import org.androidannotations.annotations.res.StringRes;

import java.util.ArrayList;
import java.util.List;

import myandroid.library.util.ApplicationHelper;

@EActivity(R.layout.activity_lab)
public class LabActivity extends BaseToolbarActivity<LabView, LabPresenter>
                                implements LabView {

    @ViewById(R.id.lab_switch_similarity)
    UISwitchButton switchSimilarity;

    @StringRes(R.string.toolbar_title_lab)
    String toolbarTitle;

    @ColorRes(R.color.colorPrimary)
    int toolbarBgColor;
    @ColorRes(R.color.textColorPrimary)
    int toolbarTextColor;

    @AfterViews
    void afterViews() {
        setupUI(this, toolbarBgColor, toolbarTextColor);

        List<ToolbarOwner.MenuAction> menuActionList = new ArrayList<>();

        ToolbarOwner.Config config = new ToolbarOwner.Config(toolbarTitle, true, R.drawable.ic_back_dark, menuActionList);
        mToolbarOwner.setConfig(config);

        String similarityState = getIntent().getStringExtra("similarityState");

        if (TextUtils.isEmpty(similarityState)) {
            presenter.getUserSimilarityState();
        } else {
            boolean isOpening = "true".equals(similarityState);
            switchSimilarity.setChecked(isOpening);
        }

        ApplicationHelper.getInstance().addActivity(this);
    }

    @NonNull
    @Override
    public LabPresenter createPresenter() {
        return new LabPresenter(this);
    }

    @CheckedChange(R.id.lab_switch_similarity)
    void checkedChangeOnSimilarityCheckBox(CompoundButton buttonView, boolean isChecked) {
            presenter.setOpenSimilarity(isChecked);
    }

    @Override
    public void setSimilarityState(boolean isOpening) {
        switchSimilarity.setChecked(isOpening);
    }
}
